<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head><title>SASAPI</title><script src="../../../quicknav.js" type="text/javascript"></script><script><!--
document.quicknavBasePath="../../../index-files";
//--></script><link href="../../../style.css" title="JavaDoc" rel="stylesheet" type="text/css"/><link href="../../../unnatural.css" title="Unnatural" rel="alternate stylesheet" type="text/css"/><link href="../../../overview-summary.html" title="Overview" rel="top"/><meta name="generator" content="http://www.badgers-in-foil.co.uk/projects/as2api/"/></head><body><pre><span class="lineno" id="1">     1  </span><span class="comment doc">/**
<span class="lineno" id="2">     2  </span> * com.sekati.log.ConsoleFPSMonitor
<span class="lineno" id="3">     3  </span> * @version 1.0.5
<span class="lineno" id="4">     4  </span> * @author jason m horwitz | sekati.com
<span class="lineno" id="5">     5  </span> * Copyright (C) 2007  jason m horwitz, Sekat LLC. All Rights Reserved.
<span class="lineno" id="6">     6  </span> * Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
<span class="lineno" id="7">     7  </span> */</span>
<span class="lineno" id="8">     8  </span>
<span class="lineno" id="9">     9  </span><span class="key">import</span> com.sekati.display.BaseClip;
<span class="lineno" id="10">    10  </span><span class="key">import</span> com.sekati.log.ConsoleStyle;
<span class="lineno" id="11">    11  </span><span class="key">import</span> com.sekati.time.FPS;
<span class="lineno" id="12">    12  </span><span class="key">import</span> com.sekati.utils.Delegate;
<span class="lineno" id="13">    13  </span>
<span class="lineno" id="14">    14  </span><span class="comment doc">/**
<span class="lineno" id="15">    15  </span> * Console FPSMonitor UI
<span class="lineno" id="16">    16  </span> * {@code Usage:
<span class="lineno" id="17">    17  </span> * var fpsMonitor:MovieClip = ClassUtils.createEmptyMovieClip (com.sekati.log.ConsoleFPSMonitor, this, "consoleFPSMonitor", {_x:750, _y:0});
<span class="lineno" id="18">    18  </span> * }
<span class="lineno" id="19">    19  </span> * @see {@link com.sekati.log.Console}
<span class="lineno" id="20">    20  </span> */</span>
<span class="lineno" id="21">    21  </span><span class="key">class</span> com.sekati.log.ConsoleFPSMonitor <span class="key">extends</span> BaseClip {
<span class="lineno" id="22">    22  </span>
<span class="lineno" id="23">    23  </span>	<span class="key">private</span> <span class="key">var</span> _fps:FPS;
<span class="lineno" id="24">    24  </span>	<span class="key">private</span> <span class="key">var</span> _cs:ConsoleStyle;
<span class="lineno" id="25">    25  </span>	<span class="key">private</span> <span class="key">var</span> _style:Object;	
<span class="lineno" id="26">    26  </span>	<span class="key">private</span> <span class="key">var</span> _bg:MovieClip;
<span class="lineno" id="27">    27  </span>	<span class="key">private</span> <span class="key">var</span> _currentLabel:TextField;
<span class="lineno" id="28">    28  </span>	<span class="key">private</span> <span class="key">var</span> _averageLabel:TextField;
<span class="lineno" id="29">    29  </span>	<span class="key">private</span> <span class="key">var</span> _currentFps:TextField;
<span class="lineno" id="30">    30  </span>	<span class="key">private</span> <span class="key">var</span> _averageFps:TextField;
<span class="lineno" id="31">    31  </span>
<span class="lineno" id="32">    32  </span>	<span class="comment doc">/**
<span class="lineno" id="33">    33  </span>	 * ConsoleFPSMonitor Constructor.
<span class="lineno" id="34">    34  </span>	 */</span>
<span class="lineno" id="35">    35  </span>	<span class="key">public</span> <span class="key">function</span> ConsoleFPSMonitor() {	
<span class="lineno" id="36">    36  </span>		<span class="comment">//trace("ConsoleFPSMonitor: "+_this._name+".__RUID = "+_this.__RUID+";");</span>
<span class="lineno" id="37">    37  </span>		_cs = ConsoleStyle.getInstance( );
<span class="lineno" id="38">    38  </span>		_style = _cs.CSS.console.head.fps;
<span class="lineno" id="39">    39  </span>		
<span class="lineno" id="40">    40  </span>		<span class="comment">// draw the bg for toClipboard presses</span>
<span class="lineno" id="41">    41  </span>		_bg = _cs.createStyledRectangle( _this, _style.bg );
<span class="lineno" id="42">    42  </span>		
<span class="lineno" id="43">    43  </span>		<span class="comment">// text - createStyledTextField (target:MovieClip, layout:Object, color:Object, str:String)</span>
<span class="lineno" id="44">    44  </span>		_currentLabel = _cs.createStyledTextField( _this, _style.textfields.current_label );
<span class="lineno" id="45">    45  </span>		_averageLabel = _cs.createStyledTextField( _this, _style.textfields.average_label );
<span class="lineno" id="46">    46  </span>		_currentFps = _cs.createStyledTextField( _this, _style.textfields.current_fps );
<span class="lineno" id="47">    47  </span>		_averageFps = _cs.createStyledTextField( _this, _style.textfields.average_fps );
<span class="lineno" id="48">    48  </span>	
<span class="lineno" id="49">    49  </span>		<span class="comment">// start monitoring	</span>
<span class="lineno" id="50">    50  </span>		_fps = <span class="key">new</span> FPS( Delegate.create( _this, updateFPS ), _style.updateRate );
<span class="lineno" id="51">    51  </span>
<span class="lineno" id="52">    52  </span>		<span class="comment">/*
<span class="lineno" id="53">    53  </span>		// events
<span class="lineno" id="54">    54  </span>		_bg.onPress = Delegate.create(_this, toClipboard);
<span class="lineno" id="55">    55  </span>		_bg.useHandCursor = false;
<span class="lineno" id="56">    56  </span>		 */</span>
<span class="lineno" id="57">    57  </span>	}
<span class="lineno" id="58">    58  </span>
<span class="lineno" id="59">    59  </span>	<span class="comment doc">/**
<span class="lineno" id="60">    60  </span>	 * Update the FPS textfields.
<span class="lineno" id="61">    61  </span>	 * @param current (Number) the current swf's FPS
<span class="lineno" id="62">    62  </span>	 * @param average (Number) the average swf's FPS since inception
<span class="lineno" id="63">    63  </span>	 * @param currentTrend (String) direction is the current fps trending: "+"|"-" 
<span class="lineno" id="64">    64  </span>	 * @param averageTrend (String) direction is the average fps trending: "+"|"-" 
<span class="lineno" id="65">    65  </span>	 */</span>
<span class="lineno" id="66">    66  </span>	<span class="key">private</span> <span class="key">function</span> updateFPS(current:Number, average:Number, currentTrend:String, averageTrend:String):Void {
<span class="lineno" id="67">    67  </span>		<span class="key">var</span> cc:Number = (currentTrend == <span class="str_const">"+"</span>) ? _style.textfields.trend_colors.up : _style.textfields.trend_colors.down;
<span class="lineno" id="68">    68  </span>		<span class="key">var</span> ac:Number = (averageTrend == <span class="str_const">"+"</span>) ? _style.textfields.trend_colors.up : _style.textfields.trend_colors.down;
<span class="lineno" id="69">    69  </span>		_currentFps.htmlText = <span class="str_const">"&lt;font color='"</span> + cc + <span class="str_const">"'&gt;"</span> + currentTrend + current + <span class="str_const">"&lt;/font&gt;"</span>;
<span class="lineno" id="70">    70  </span>		_averageFps.htmlText = <span class="str_const">"&lt;font color='"</span> + ac + <span class="str_const">"'&gt;"</span> + averageTrend + average + <span class="str_const">"&lt;/font&gt;"</span>;
<span class="lineno" id="71">    71  </span>	}	
<span class="lineno" id="72">    72  </span>
<span class="lineno" id="73">    73  </span>	<span class="comment doc">/**
<span class="lineno" id="74">    74  </span>	 * Copy FPS string data to clipboard.
<span class="lineno" id="75">    75  </span>	 * @return Void
<span class="lineno" id="76">    76  </span>	 */</span>
<span class="lineno" id="77">    77  </span>	<span class="key">public</span> <span class="key">function</span> toClipboard():Void {
<span class="lineno" id="78">    78  </span>		System.setClipboard( toString( ) );
<span class="lineno" id="79">    79  </span>	}
<span class="lineno" id="80">    80  </span>
<span class="lineno" id="81">    81  </span>	<span class="comment doc">/**
<span class="lineno" id="82">    82  </span>	 * Return FPS string data
<span class="lineno" id="83">    83  </span>	 * @return String
<span class="lineno" id="84">    84  </span>	 */</span>
<span class="lineno" id="85">    85  </span>	<span class="key">public</span> <span class="key">function</span> toString():String {
<span class="lineno" id="86">    86  </span>		<span class="key">var</span> tab:String = <span class="str_const">"\t"</span>;
<span class="lineno" id="87">    87  </span>		<span class="key">var</span> str:String = <span class="str_const">"FPS:"</span> + tab + _currentLabel.text + <span class="str_const">": "</span> + _currentFps.text + tab + _averageLabel.text + <span class="str_const">": "</span> + _averageFps.text;	
<span class="lineno" id="88">    88  </span>		<span class="key">return</span> str;
<span class="lineno" id="89">    89  </span>	}
<span class="lineno" id="90">    90  </span>
<span class="lineno" id="91">    91  </span>	<span class="comment doc">/**
<span class="lineno" id="92">    92  </span>	 * calls superclasses BaseClip.destroy and executes its own destroy behaviors.
<span class="lineno" id="93">    93  </span>	 * @return Void
<span class="lineno" id="94">    94  </span>	 */</span>
<span class="lineno" id="95">    95  </span>	<span class="key">public</span> <span class="key">function</span> destroy():Void {
<span class="lineno" id="96">    96  </span>		_fps.destroy( );
<span class="lineno" id="97">    97  </span>		<span class="key">super</span>.destroy( );
<span class="lineno" id="98">    98  </span>	}	
<span class="lineno" id="99">    99  </span>}</pre><ul class="main_nav" id="main_nav"><li><a href="../../../overview-summary.html" title="Overview of SASAPI" class="button">Overview</a></li><li><a href="package-summary.html" title="Overview of package com.sekati.log" class="button">Package</a></li><li><a href="ConsoleFPSMonitor.html" title="Detail of com.sekati.log.ConsoleFPSMonitor API" class="button">Class</a></li><li><span class="button nav_current">Source</span></li><li><a href="../../../index-files/index.html" title="Alpabetical index of types and members" class="button">Index</a></li></ul><div class="footer"><a href="http://www.badgers-in-foil.co.uk/projects/as2api/" title="ActionScript 2 API Documentation Generator">as2api</a></div></body></html>